$(function(){ 
	var t1 = window.setInterval(function() {
		var w = $('.box-body').width() + "";
		if (w != '0') {
			var width = parseInt(w)-5+'px' ;		
			$("#breakerXihu").css("width", width);
			$("#property").css("width", width);
			myChart.getChart().resize();
			arcChart.getChart().resize();
			window.clearInterval(t1);
		}
	}, 20);
	var breakerId=$("#breakerId").val();
	breakername=$("#breakerName").val();
	getArcTime(breakerId);
});

var breakername;
var arc_time = [];
var arcChart=new CategoryLine("breakerXihu");
var xAxis=arcChart.getxAxis();
xAxis.type='time';
function getArcTime(breakerId){
	$.getJSON("/rest/riskwarning/getBreakerArcTimesById/"+breakerId,function(result){			
		if(result.length!='0'){
			arc_time=result[0].value;
			initArcChart();
			initDensityChart();//正态分布
		}else{
			alert('该断路器无动作!');
		}
		
	});
}
function initArcChart(){
	arcChart.setyAxis(arc_time);
	arcChart.setyAxisName(breakername);
	var opt=arcChart.getOption();
	opt.toolbox.feature.dataView.optionToContent=function(opt){
	    var series = opt.series;
	    var table = '<table border="1" style="width:100%;text-align:center"><tbody><tr>';
	    for(var j=0;j<series.length;j++){
	    	table = table + '<td colspan=2>' + series[j].name + '</td></tr><tr>';
	    	for (var i = 0, l = series[j].data.length; i < l; i++) {
		        table += '<td>' + series[j].data[i][0] + '</td><td>'+series[j].data[i][1]+'</td></tr>';
		    }
	    }	    
	    table += '</tbody></table>';
	    return table;
	};
	opt.series[0].label.normal.show=false;
	opt.grid.bottom=10;
	arcChart.setxAxisTitle('日期').setyAxisTitle("熄弧时间/ms").show();
	
}
var abnormalArcTime=[];
var myChart=new Category2YLine('property');
function initDensityChart(){
	// 概率分布
	var pro_density = [ 4, 3, 3, 3, 3, 3, 4, 4, 3.332, 4.165, 4.998, 4.998, 5.831,
			2.500, 4.166, 4.166, 3.332, 2.499, 3.332, 4.165, 4.165, 4.165, 4.165,
			2.499, 3.332, 3.332, 3.332, 3.332, 4.000, 2.500, 3.333, 4.166, 3.333,
			4.167, 6.666, 3.333, 3.333, 3.333, 2.198, 4.166, 4.167, 5.833, 3.333,
			3.332, 4.998, 3.332, 4.998, 4.998, 4.165, 5.000, 2.000, 4.165, 3.334,
			5.000, 4.167, 4.166, 3.332, 4.165, 3.332, 4.166, 5.831, 4.167, 4.165,
			7.000, 4.165, 3.334, 5.833, 5.831, 4.998, 0.937, 3.333, 6.000, 5.000,
			5.831, 4.166, 4.165, 4.998, 5.000, 5.833, 6.667, 5.833 ];
	// 频率
	var frequency = [ 0, 2, 0, 2, 5, 5, 20, 4, 23, 10, 0, 8, 0, 3, 0, 0 ];
	// 熄弧时间
	var xihu_avg_time = [ 0.6, 1.1, 1.6, 2.1, 2.6, 3.1, 3.6, 4.1, 4.6, 5.1, 6.1,
			6.6, 7.1, 7.6, 8.1 ];
	var gd = new GaussianDistribution(pro_density);
	var obj=gd.getXData();
	var yData = gd.proDensity(xihu_avg_time);
	myChart.setxAxis(xihu_avg_time);
	myChart.sety1Axis(frequency);
	myChart.setyAxisName('频率');
	for(var i in yData){
		yData[i] = yData[i].toFixed(2);
	}
	myChart.sety2Axis(yData);
	myChart.setyAxisName('概率密度');
	var opt=myChart.getOption();
	opt.grid.bottom=10;
	opt.series[0].type='bar';
	opt.series[1].smooth=true;
	opt.series[1].areaStyle.normal.opacity=0;
	opt.series[1].showSymbol=false;
	myChart.show();
	abnormalArcTime=gd.abnormalAnalyse(arc_time);
	abnormalShow();
}
function abnormalShow(){
	var opt=MyTable.getDefaultOptions();
	var tb = new MyTable('abnormalArcTime',['日期','熄弧时间/ms'],opt);
	 tb.setDataSet(abnormalArcTime);
	 tb.show();
}
